package de.dailab.graphworld.bean;

import de.dailab.graphworld.world.GraphWorldAgentBean;
import de.dailab.jiactng.agentcore.action.Action;
import de.dailab.jiactng.agentcore.ontology.IActionDescription;
import java.io.Serializable;

/**
 * An abstract implementation of a {@link BeanTeamMember} that occurs in the
 * graph world. Scouts and carriers are implementations of this class, broker
 * not.
 *
 * @author Kseniya
 */
public abstract class BeanPhysical extends BeanTeamMember {

    private IActionDescription actionInit;

    @Override
    public void doStart() {
        super.doStart();
        actionInit = thisAgent.searchAction(new Action(GraphWorldAgentBean.ACTION_INIT_TEAM_POSITION));
    }

    @Override
    public void execute() {
        if (!isInitialisedInWorld()) {
            initialiseInWorld();
        }
    }

    /**
     * Per default, the team member is not placed in world at the first
     * execute(...) call, so an appropriate action must be invoked to assign
     * this bean to a team.
     *
     * @return
     */
    protected boolean isInitialisedInWorld() {
        return false;
    }

    private void initialiseInWorld() {
        this.invoke(actionInit, new Serializable[]{getTeamName()}, this);
    }
}
